using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 仓库控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class WarehouseController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public WarehouseController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取仓库列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<WarehouseDto>>> GetWarehouses([FromQuery] WarehouseQueryDto query)
        {
            return await _consoleService.GetWarehousesAsync(query);
        }

        /// <summary>
        /// 获取仓库详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<WarehouseDto>> GetWarehouse(int id)
        {
            return await _consoleService.GetWarehouseAsync(id);
        }

        /// <summary>
        /// 创建仓库
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<WarehouseDto>> CreateWarehouse([FromBody] WarehouseDto dto)
        {
            return await _consoleService.CreateWarehouseAsync(dto);
        }

        /// <summary>
        /// 更新仓库
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<WarehouseDto>> UpdateWarehouse([FromBody] WarehouseDto dto)
        {
            return await _consoleService.UpdateWarehouseAsync(dto);
        }

        /// <summary>
        /// 删除仓库
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeleteWarehouse(int id)
        {
            return await _consoleService.DeleteWarehouseAsync(id);
        }
    }
} 